import datetime

from greatwall.models import Card

class CardOperations(object):

    def __init__(self):
        pass

    def get_card_by_id(self, card_id):
        card = Card.objects.get(id=card_id)
        return card

    def create_card(self, title='', stage=None, start_dt='', 
                    end_dt='', devs='', desc=''):
        card = Card()
        card.title = title
        card.fk_stage = stage
        card.date_created = datetime.datetime.today()
        #card.start_date = start_dt
        #card.end_date = end_dt
        card.developers = devs
        card.description = desc
        card.save()
        return card

    def create_dummy_card(self, stage=None, title=''):
        tendays = datetime.timedelta(days=10)
        today = datetime.datetime.today()
        card = self.create_card(title=title, stage=stage,
                                start_dt=today, end_dt=today+tendays,
                                devs='Jayesh/Arun', desc='this is a dummy card')

    def toogle_card(self, card):
        toogle_dict = {True: False, False: True}
        card.is_open = toogle_dict[card.is_open]
        card.save()
